<template>
  <div class="login-container">
    <el-row>
      <el-col :xs="24" :sm="24" :md="12" :lg="16" :xl="16">
        <div style="color: transparent">占位符</div>
      </el-col>
      <el-col :xs="24" :sm="24" :md="12" :lg="8" :xl="8">
        <div class="title-tips">欢迎来到教师管理考评系统</div>
      </el-col>
    </el-row>
  </div>
</template>


<script>
  import {login} from '@/api/login';

  export default {
    name: 'Login',
    data() {
      return {
        //code
        code:'',
        appid: ''

      }
    },
    created () {
      this.appid = window.sessionStorage.getItem('appid')
      this.code = this.parseToken(this.$route.fullPath)

    },
    destroyed() {
    },
    methods: {
      //截取路由获取参数
      parseToken(fullPath) {
        // QQ返回的access_token是在#后的，需要进行特殊解析
        if (fullPath) {
          // 取最后一个位置的#
          let idx = fullPath.lastIndexOf("?");
          if (idx === -1) {
            return null;
          }
          var restStr = fullPath.substring(idx+1);
          if (!restStr) {
            return null;
          }

          restStr = restStr
            .split("&")
            .find((str) => str.includes("code="));
          if (!restStr) {
            return null;
          }
          const code = restStr.substring(5);
          //用户登录
          login({"code":code, 'appid': this.appid})
            .then((res) => {
              if (res.code !== "200") {
                this.$message.error(res.msg)
                this.loading = false
              }else{
                this.$message.success(res.msg)
                window.sessionStorage.setItem('token',res.data.token)
                window.sessionStorage.setItem('avatar',res.data.avatar)
                window.sessionStorage.setItem('mobile',res.data.mobile)
                window.sessionStorage.setItem('name',res.data.name)
                window.sessionStorage.setItem('role',res.data.role)
                this.$router.push({ path: this.redirect || '/'})
                this.loading = false
              }
            })
            .catch(() => {
            })
          return restStr.substring(5);
        }
      }

    }
  }
</script>


<style lang="scss" scoped>
  .login-container {
    height: 100vh;
    background: url("~@/assets/images/background.jpg") center center fixed
    no-repeat;
    background-size: cover;

    .title {
      font-size: 54px;
      font-weight: 500;
      color: rgba(14, 18, 26, 1);
    }

    .title-tips {
      margin-top: 160px;
      font-size: 26px;
      font-weight: 400;
      color: rgba(14, 18, 26, 1);
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .login-btn {
      display: inherit;
      width: 220px;
      height: 60px;
      margin-top: 5px;
      border: 0;

      &:hover {
        opacity: 0.9;
      }
    }

    .login-form {
      position: relative;
      max-width: 100%;
      margin: calc((100vh - 425px) / 2) 10% 10%;
      overflow: hidden;

      .forget-password {
        width: 100%;
        margin-top: 40px;
        text-align: left;

        .forget-pass {
          width: 129px;
          height: 19px;
          font-size: 20px;
          font-weight: 400;
          color: rgba(92, 102, 240, 1);
        }
      }
    }

    .tips {
      margin-bottom: 10px;
      font-size: 14px;
      color: #fff;

      span {
        &:first-of-type {
          margin-right: 16px;
        }
      }
    }

    .title-container {
      position: relative;

      .title {
        margin: 0 auto 40px auto;
        font-size: 34px;
        font-weight: bold;
        color: #1890ff;
        text-align: center;
      }
    }

    .svg-container {
      position: absolute;
      top: 14px;
      left: 15px;
      z-index: 999;
      font-size: 16px;
      color: #d7dee3;
      cursor: pointer;
      user-select: none;
    }

    .show-password {
      position: absolute;
      top: 14px;
      right: 25px;
      font-size: 16px;
      color: #d7dee3;
      cursor: pointer;
      user-select: none;
    }

    ::v-deep {
      .el-form-item {
        padding-right: 0;
        margin: 20px 0;
        color: #454545;
        background: transparent;
        border: 1px solid transparent;
        border-radius: 2px;

        &__content {
          min-height: 32px;
          line-height: 32px;
        }

        &__error {
          position: absolute;
          top: 100%;
          left: 18px;
          font-size: 12px;
          line-height: 18px;
          color: #ff4d4f;
        }
      }

      .el-input {
        box-sizing: border-box;

        input {
          height: 58px;
          padding-left: 45px;
          font-size: 14px;
          line-height: 58px;
          color: #606266;
          background: #f6f4fc;
          border: 0;
          caret-color: #606266;
        }
      }
    }
  }
</style>
